/**
 * Copyright (C), 2001-2031, www.bosssof.com.cn
 * FileName: SpecialPathFile.java
 * Author: ckj
 * Date: 2024/7/21 下午10:13
 * Description:
 * 用户将文件发给特定的人
 * History:
 * Date          Author   Version  Desc
 * 2024-01-01    bosssoft  1.0.0   initialize this file
 */
package com.bosssoft.message;

import com.bosssoft.constants.MessageTypeConstant;
import com.bosssoft.utils.ReaderUtil;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;


/**
 * @author ckj
 */
public class SpecialPathFile extends BaseMessage{
    private String targetUserName;
    private List<String> fileContent;
    private String fileName;
    @Override
    public BaseMessage parse(BufferedReader reader, Integer type) throws Exception {
        this.setTargetUserName(ReaderUtil.readLineWithAes(reader));
        this.fileName = ReaderUtil.readLineWithAes(reader);
        processContent(reader);
        return this;
    }

    /**
     *
     * @author ckj
     * @date 2024/07/22 下午10:44
     * 从输入流中读取指定数量的内容行，并将其存储在对象的 content 属性
     * @param reader
     * @return void
     */
    private void processContent(BufferedReader reader) throws Exception {
        int contentLength = Integer.parseInt(ReaderUtil.readLineWithAes(reader));
        this.fileContent = new ArrayList<>();
        for (int i = 0; i < contentLength; i++) {
            this.fileContent.add(ReaderUtil.readLineWithAes(reader));
        }
        ReaderUtil.readLineWithAes(reader);
    }

    /**
     *
     * @author ckj
     * @date 2024/07/22 下午10:45
     * 创建一个具有特定结构和数据的 SpecialPathFile 对象
     * @param targetUserName
     * @param fileName
     * @param fileContent
     * @return com.bosssoft.message.SpecialPathFile
     */
    public SpecialPathFile sendMessageBuild(String targetUserName,String fileName, List<String> fileContent) {
        this.setType(MessageTypeConstant.SEND_FILES_TO_SPECIFIC_USERS);
        this.setHeader(new ArrayList<>());
        this.getHeader().add(targetUserName);
        this.getHeader().add(fileName);
        this.setContent(fileContent);
        return this;
    }

    public String getTargetUserName() {
        return targetUserName;
    }

    public void setTargetUserName(String targetUserName) {
        this.targetUserName = targetUserName;
    }

    public List<String> getFileContent() {
        return fileContent;
    }

    public String getFileName() {
        return fileName;
    }
}